package test.demo;

import cn.hutool.core.util.ArrayUtil;
import tech.waterism.modelbase.PredictBase;
import tech.waterism.modelbase.PredictResult;
import com.alibaba.fastjson.JSON;

import java.util.*;

import static jxl.biff.BaseCellFeatures.logger;

/**
 * 降雨径流相关图(P+Pa-R)模型
 * 累积算法考虑预报时刻Pa
 *
 * @author 初京刚
 * @version 1.0
 */
public class P_RWLL extends PredictBase {

    /**
     * 前期土壤含水量
     */
    private double pa0Initial;

    /**
     * 查线方式代码，等于1表示用累计雨量查曲线，不等于1表示用时段雨量查曲线
     */
    private int calculatedType;

    /**
     * 土壤最大初损量Im
     */
    private double im;

    /**
     * 12个月的土壤含水量日衰减系数KD
     */
    private double[] kd;

    /**
     * P～R曲线的节点数M
     */
    private int m;

    /**
     * P～R曲线
     */
    private double[][] pr;

    /**
     * 降水时间
     */
    private Date[] floodTm;

    /**
     * 预报开始时间
     */
    private Date startTm;

    /**
     * 预报开始数组下标
     */
    private int startIndex;

    /**
     * 降水量
     */
    private double[] floodDrp;

    /**
     * 降水序列长度
     */
    private Integer floodRainRange;

    /**
     * 降水时段长
     */
    private double timeInterval;

    /**
     * 土壤含水量模拟过程
     */
    private double[] paSim;

    /**
     * 模拟总产流
     */
    private double[] runoffSim;

    public P_RWLL(Map<String, String> data) {
        super();
        pa0Initial = Double.parseDouble(data.get("PA0"));                      // 前期土壤含水量
        calculatedType = Integer.parseInt(data.get("CalculatedType"));         // line 3 查曲线方式代码，等于1表示用累计雨量查曲线，不等于1表示用时段雨量查曲线
        im = Double.parseDouble(data.get("Im"));                               // line 4 土壤最大初损量Im
        kd = JSON.parseObject(data.get("KD"), double[].class);                 // line 5 12个月的土壤含水量日衰减系数KD
        m = Integer.parseInt(data.get("M"));                                   // line 6 P～R曲线的节点数M
        pr = JSON.parseObject(data.get("PR"), double[][].class);               // line 7 开始取到最后 P～R曲线：其中第一列为序号 需要去掉; 第2列为降雨
        floodTm = JSON.parseObject(data.get("dt"), Date[].class);              // input[i].data.dt
        startTm  = JSON.parseObject(data.get("start"), Date.class);
        startIndex = ArrayUtil.indexOf(floodTm, startTm);
        floodDrp = JSON.parseObject(data.get("rain"), double[].class);         // input[i].data.rain
        floodRainRange = floodDrp.length;
        timeInterval = Double.parseDouble(data.get("clen"));                   // index.clen
        paSim = new double[floodRainRange + 1];
        runoffSim = new double[floodRainRange];
    }

    /**
     * 模型计算
     */
    public Map<String, double[]> PRWLLmodel() {

        //降雨径流相关图计算
        ppluspar();

        Map<String, double[]> simulationResult = new HashMap<>();

        simulationResult.put("rain", floodDrp);
        simulationResult.put("runoffSim", runoffSim);
        return simulationResult;
    }

    /**
     * 降雨径流相关图
     *
     * @return 产流
     */
    private void ppluspar() {

        double sumR1 = 0, sumR2 = 0, paa, sumP1 = 0, sumP2 = 0;
        paSim[0] = pa0Initial;
        if (calculatedType != 1) {
            for (int i = 0; i < floodRainRange; i++) {
                sumP1 = floodDrp[i];
                sumR1 = insert2(paSim[i], pr[0], pr[1], pr[1].length);
                sumR2 = insert2(sumP1 + paSim[i], pr[0], pr[1], pr[1].length) - sumR1;
                if (sumR2 > floodDrp[i]) {
                    runoffSim[i] = floodDrp[i];
                } else if (sumR2 < 0.0) {
                    runoffSim[i] = 0.0f;
                } else {
                    runoffSim[i] = sumR2;
                }
                Calendar time = Calendar.getInstance();
                time.setTime(floodTm[i]);
                Integer month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份
                double ka0 = kd[month - 1];
                double D = 24 / timeInterval;
                double ka = Math.pow(ka0, 1.0 / D);

                /*需保留最后一个时段末的状态值，去掉时段初值限制条件*/
                //                if(i + 1 < floodRainRange){
                paSim[i + 1] = ka * (paSim[i] + floodDrp[i]);
                if (paSim[i + 1] >= im) {
                    paSim[i + 1] = im;
                }
                //                }
            }
        } else {
            if(startIndex == 0) {
                for (int i = 0; i < floodRainRange; i++) {
                    sumP2 += floodDrp[i];
                    sumR2 = insert2(sumP2 + paSim[startIndex], pr[0], pr[1], pr[1].length);
                    if (i == startIndex) {
                        sumR1 = insert2(paSim[startIndex], pr[0], pr[1], pr[1].length);
                    }
                    runoffSim[i] = sumR2 - sumR1;
                    if (runoffSim[i] > floodDrp[i]) {
                        runoffSim[i] = floodDrp[i];
                    }
                    if (runoffSim[i] < 0.0) {
                        runoffSim[i] = 0.0f;
                    }
                    sumR1 = sumR2;
                    Calendar time = Calendar.getInstance();
                    time.setTime(floodTm[i]);
                    Integer month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份
                    double ka0 = kd[month - 1];
                    double D = 24 / timeInterval;
                    double ka = Math.pow(ka0, 1.0 / D);

                    /*需保留最后一个时段末的状态值，去掉时段初值限制条件*/
                    //                if(i + 1 < floodRainRange){
                    paSim[i + 1] = ka * (paSim[i] + floodDrp[i]);
                    if (paSim[i + 1] >= im) {
                        paSim[i + 1] = im;
                    }

                    //                }
                }
            } else {
                for (int i = 0; i < floodRainRange; i++) {
                    if(i < startIndex) {
                        sumP1 += floodDrp[i];
                        sumR2 = insert2(sumP1 + pa0Initial, pr[0], pr[1], pr[1].length);
                        if (i == 0) {
                            sumR1 = insert2(pa0Initial, pr[0], pr[1], pr[1].length);
                        }
                        runoffSim[i] = sumR2 - sumR1;
                        if (runoffSim[i] > floodDrp[i]) {
                            runoffSim[i] = floodDrp[i];
                        }
                        if (runoffSim[i] < 0.0) {
                            runoffSim[i] = 0.0f;
                        }
                        sumR1 = sumR2;
                        Calendar time = Calendar.getInstance();
                        time.setTime(floodTm[i]);
                        Integer month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份
                        double ka0 = kd[month - 1];
                        double D = 24 / timeInterval;
                        double ka = Math.pow(ka0, 1.0 / D);

                        /*需保留最后一个时段末的状态值，去掉时段初值限制条件*/
                        //                if(i + 1 < floodRainRange){
                        paSim[i + 1] = ka * (paSim[i] + floodDrp[i]);
                        if (paSim[i + 1] >= im) {
                            paSim[i + 1] = im;
                        }
                    } else {
                        sumP2 += floodDrp[i];
                        sumR2 = insert2(sumP2 + paSim[startIndex], pr[0], pr[1], pr[1].length);
                        if (i == startIndex) {
                            sumR1 = insert2(paSim[startIndex], pr[0], pr[1], pr[1].length);
                        }
                        runoffSim[i] = sumR2 - sumR1;
                        if (runoffSim[i] > floodDrp[i]) {
                            runoffSim[i] = floodDrp[i];
                        }
                        if (runoffSim[i] < 0.0) {
                            runoffSim[i] = 0.0f;
                        }
                        sumR1 = sumR2;
                        Calendar time = Calendar.getInstance();
                        time.setTime(floodTm[i]);
                        Integer month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份
                        double ka0 = kd[month - 1];
                        double D = 24 / timeInterval;
                        double ka = Math.pow(ka0, 1.0 / D);

                        /*需保留最后一个时段末的状态值，去掉时段初值限制条件*/
                        //                if(i + 1 < floodRainRange){
                        paSim[i + 1] = ka * (paSim[i] + floodDrp[i]);
                        if (paSim[i + 1] >= im) {
                            paSim[i + 1] = im;
                        }
                    }
                    //                }
                }
            }



        }


        /*
        for (int i = 0; i < floodRainRange; i++){

            if (i == 0){
                if (calculatedType != 1){
                    sumR1 = 0;
                    sumR2 = insert2(paSim[i], pr[0], pr[1], pr[1].length);
                } else {
                    sumR1 = insert2(pa0Initial, pr[0], pr[1], pr[1].length);
                }
            }

           if (calculatedType != 1){
                sumP = floodDrp[i];
                sumR1 = 0;
                sumR2 = insert2(sumP + paSim[i], pr[0], pr[1], pr[1].length);
            } else {
                sumP += floodDrp[i];
                sumR2 = insert2(sumP + pa0Initial, pr[0], pr[1], pr[1].length);
            }
            runoffSim[i] = sumR2 - sumR1;
            if (runoffSim[i] > floodDrp[i]) {
                runoffSim[i] = floodDrp[i];
            }
            if (runoffSim[i] < 0.0) {
                runoffSim[i] = 0.0f;
            }
            sumR1 = sumR2;

            Calendar time = Calendar.getInstance();
            time.setTime(floodTm[i]);
            Integer month = time.get(Calendar.MONTH) + 1; // 获得降雨开始月份

            double ka0 = kd[month - 1];
            double ka = 1.0f - (1.0f - ka0) / (24.0f / timeInterval);
            if(i + 1 < floodRainRange){
                paSim[i + 1] = ka * (paSim[i] + floodDrp[i]);
                if (paSim[i + 1] >= im)
                {
                    paSim[i + 1] = im;
                }
            }
        }
        */

    }

    /**
     * 插值计算径流量
     *
     * @param p    降雨量
     * @param ppa  Pa值
     * @param pr   净雨
     * @param i_pr P-Pa模型长度
     * @return 一个含净雨和前期影响雨量的数组
     */
    private double calculateR(double p, double[] ppa, double[] pr, int i_pr) {
        double rsim = insert2(p, ppa, pr, i_pr);
        if (rsim > p) {
            rsim = p;
        }
        if (rsim < 0) {
            rsim = 0;
        }
        return rsim;
    }

    /**
     * 插值计算
     *
     * @param x0
     * @param x
     * @param y
     * @param n
     * @return
     */
    public double insert2(double x0, double x[], double y[], int n) { // 两点插值(float)
        if (n <= 1) {
            return 0;
        }
        int i;
        double y0, x1, x2;
        if (x[0] < x[n - 1]) { // *x[] is ascending
            for (i = 0; i < n; i++) {
                if (x0 <= x[i]) {
                    break;
                }
            }
        } else { // *x[] is descending
            for (i = 0; i < n; i++) {
                if (x0 >= x[i]) {
                    break;
                }
            }
        }
        if (i >= n - 1) {
            i = n - 2;
        } else if (i <= 1) {
            i = 0;
        } else {
            i--;
        }
        x1 = x[i];
        x2 = x[i + 1];
        if (x1 == x2) {
            return y[i];
        }
        y0 = y[i] + (x0 - x1) / (x2 - x1) * (y[i + 1] - y[i]);

        return y0;
    }

    private List<String> toStringList(double[] array0) {
        String[] array = new String[array0.length];
        for (int i = 0; i < array.length; i++) {
            array[i] = String.valueOf(array0[i]);
        }
        return Arrays.asList(array);
    }

    @Override
    public void init() {

    }

    @Override
    public PredictResult predict() {
        PredictResult result = new PredictResult();
        Map<String, double[]> map = PRWLLmodel();
        double[][] RSim = new double[1][];
        RSim[0] = map.get("runoffSim");

        result.setRunoffSim(map.get("runoffSim"));
        result.setRSim(RSim);

        // 更新状态
        List<String> PA = toStringList(paSim);
        Map<String, List<String>> status = new HashMap<>();
        status.put("PA0", PA);
        result.setNewStatus(status);
        return result;
    }

    public static void main(String[] args) {
        String a = "{\"dt\":\"[\\\"2021-06-02 08:00:00\\\",\\\"2021-06-02 14:00:00\\\",\\\"2021-06-02 20:00:00\\\",\\\"2021-06-03 02:00:00\\\",\\\"2021-06-03 08:00:00\\\",\\\"2021-06-03 14:00:00\\\",\\\"2021-06-03 20:00:00\\\",\\\"2021-06-04 02:00:00\\\",\\\"2021-06-04 08:00:00\\\",\\\"2021-06-04 14:00:00\\\",\\\"2021-06-04 20:00:00\\\",\\\"2021-06-05 02:00:00\\\",\\\"2021-06-05 08:00:00\\\",\\\"2021-06-05 14:00:00\\\",\\\"2021-06-05 20:00:00\\\",\\\"2021-06-06 02:00:00\\\",\\\"2021-06-06 08:00:00\\\",\\\"2021-06-06 14:00:00\\\",\\\"2021-06-06 20:00:00\\\",\\\"2021-06-07 02:00:00\\\",\\\"2021-06-07 08:00:00\\\",\\\"2021-06-07 14:00:00\\\",\\\"2021-06-07 20:00:00\\\",\\\"2021-06-08 02:00:00\\\",\\\"2021-06-08 08:00:00\\\",\\\"2021-06-08 14:00:00\\\",\\\"2021-06-08 20:00:00\\\",\\\"2021-06-09 02:00:00\\\",\\\"2021-06-09 08:00:00\\\",\\\"2021-06-09 14:00:00\\\",\\\"2021-06-09 20:00:00\\\",\\\"2021-06-10 02:00:00\\\",\\\"2021-06-10 08:00:00\\\",\\\"2021-06-10 14:00:00\\\",\\\"2021-06-10 20:00:00\\\",\\\"2021-06-11 02:00:00\\\",\\\"2021-06-11 08:00:00\\\",\\\"2021-06-11 14:00:00\\\",\\\"2021-06-11 20:00:00\\\",\\\"2021-06-12 02:00:00\\\",\\\"2021-06-12 08:00:00\\\",\\\"2021-06-12 14:00:00\\\",\\\"2021-06-12 20:00:00\\\",\\\"2021-06-13 02:00:00\\\",\\\"2021-06-13 08:00:00\\\",\\\"2021-06-13 14:00:00\\\",\\\"2021-06-13 20:00:00\\\",\\\"2021-06-14 02:00:00\\\",\\\"2021-06-14 08:00:00\\\",\\\"2021-06-14 14:00:00\\\",\\\"2021-06-14 20:00:00\\\",\\\"2021-06-15 02:00:00\\\",\\\"2021-06-15 08:00:00\\\",\\\"2021-06-15 14:00:00\\\",\\\"2021-06-15 20:00:00\\\",\\\"2021-06-16 02:00:00\\\",\\\"2021-06-16 08:00:00\\\",\\\"2021-06-16 14:00:00\\\",\\\"2021-06-16 20:00:00\\\",\\\"2021-06-17 02:00:00\\\",\\\"2021-06-17 08:00:00\\\",\\\"2021-06-17 14:00:00\\\",\\\"2021-06-17 20:00:00\\\",\\\"2021-06-18 02:00:00\\\",\\\"2021-06-18 08:00:00\\\",\\\"2021-06-18 14:00:00\\\",\\\"2021-06-18 20:00:00\\\",\\\"2021-06-19 02:00:00\\\",\\\"2021-06-19 08:00:00\\\",\\\"2021-06-19 14:00:00\\\",\\\"2021-06-19 20:00:00\\\",\\\"2021-06-20 02:00:00\\\",\\\"2021-06-20 08:00:00\\\",\\\"2021-06-20 14:00:00\\\",\\\"2021-06-20 20:00:00\\\",\\\"2021-06-21 02:00:00\\\",\\\"2021-06-21 08:00:00\\\",\\\"2021-06-21 14:00:00\\\",\\\"2021-06-21 20:00:00\\\",\\\"2021-06-22 02:00:00\\\",\\\"2021-06-22 08:00:00\\\",\\\"2021-06-22 14:00:00\\\",\\\"2021-06-22 20:00:00\\\",\\\"2021-06-23 02:00:00\\\",\\\"2021-06-23 08:00:00\\\",\\\"2021-06-23 14:00:00\\\",\\\"2021-06-23 20:00:00\\\",\\\"2021-06-24 02:00:00\\\",\\\"2021-06-24 08:00:00\\\",\\\"2021-06-24 14:00:00\\\",\\\"2021-06-24 20:00:00\\\",\\\"2021-06-25 02:00:00\\\",\\\"2021-06-25 08:00:00\\\",\\\"2021-06-25 14:00:00\\\",\\\"2021-06-25 20:00:00\\\",\\\"2021-06-26 02:00:00\\\",\\\"2021-06-26 08:00:00\\\",\\\"2021-06-26 14:00:00\\\",\\\"2021-06-26 20:00:00\\\",\\\"2021-06-27 02:00:00\\\",\\\"2021-06-27 08:00:00\\\",\\\"2021-06-27 14:00:00\\\",\\\"2021-06-27 20:00:00\\\",\\\"2021-06-28 02:00:00\\\",\\\"2021-06-28 08:00:00\\\",\\\"2021-06-28 14:00:00\\\",\\\"2021-06-28 20:00:00\\\",\\\"2021-06-29 02:00:00\\\",\\\"2021-06-29 08:00:00\\\",\\\"2021-06-29 14:00:00\\\",\\\"2021-06-29 20:00:00\\\",\\\"2021-06-30 02:00:00\\\",\\\"2021-06-30 08:00:00\\\",\\\"2021-06-30 14:00:00\\\",\\\"2021-06-30 20:00:00\\\",\\\"2021-07-01 02:00:00\\\",\\\"2021-07-01 08:00:00\\\",\\\"2021-07-01 14:00:00\\\",\\\"2021-07-01 20:00:00\\\",\\\"2021-07-02 02:00:00\\\",\\\"2021-07-02 08:00:00\\\",\\\"2021-07-02 14:00:00\\\",\\\"2021-07-02 20:00:00\\\",\\\"2021-07-03 02:00:00\\\",\\\"2021-07-03 08:00:00\\\",\\\"2021-07-03 14:00:00\\\",\\\"2021-07-03 20:00:00\\\",\\\"2021-07-04 02:00:00\\\",\\\"2021-07-04 08:00:00\\\",\\\"2021-07-04 14:00:00\\\",\\\"2021-07-04 20:00:00\\\",\\\"2021-07-05 02:00:00\\\",\\\"2021-07-05 08:00:00\\\",\\\"2021-07-05 14:00:00\\\",\\\"2021-07-05 20:00:00\\\",\\\"2021-07-06 02:00:00\\\",\\\"2021-07-06 08:00:00\\\",\\\"2021-07-06 14:00:00\\\",\\\"2021-07-06 20:00:00\\\",\\\"2021-07-07 02:00:00\\\",\\\"2021-07-07 08:00:00\\\",\\\"2021-07-07 14:00:00\\\",\\\"2021-07-07 20:00:00\\\",\\\"2021-07-08 02:00:00\\\",\\\"2021-07-08 08:00:00\\\",\\\"2021-07-08 14:00:00\\\",\\\"2021-07-08 20:00:00\\\",\\\"2021-07-09 02:00:00\\\",\\\"2021-07-09 08:00:00\\\",\\\"2021-07-09 14:00:00\\\",\\\"2021-07-09 20:00:00\\\",\\\"2021-07-10 02:00:00\\\",\\\"2021-07-10 08:00:00\\\",\\\"2021-07-10 14:00:00\\\",\\\"2021-07-10 20:00:00\\\",\\\"2021-07-11 02:00:00\\\",\\\"2021-07-11 08:00:00\\\",\\\"2021-07-11 14:00:00\\\",\\\"2021-07-11 20:00:00\\\",\\\"2021-07-12 02:00:00\\\",\\\"2021-07-12 08:00:00\\\",\\\"2021-07-12 14:00:00\\\",\\\"2021-07-12 20:00:00\\\",\\\"2021-07-13 02:00:00\\\",\\\"2021-07-13 08:00:00\\\",\\\"2021-07-13 14:00:00\\\",\\\"2021-07-13 20:00:00\\\",\\\"2021-07-14 02:00:00\\\",\\\"2021-07-14 08:00:00\\\",\\\"2021-07-14 14:00:00\\\",\\\"2021-07-14 20:00:00\\\",\\\"2021-07-15 02:00:00\\\",\\\"2021-07-15 08:00:00\\\",\\\"2021-07-15 14:00:00\\\",\\\"2021-07-15 20:00:00\\\",\\\"2021-07-16 02:00:00\\\",\\\"2021-07-16 08:00:00\\\",\\\"2021-07-16 14:00:00\\\",\\\"2021-07-16 20:00:00\\\",\\\"2021-07-17 02:00:00\\\",\\\"2021-07-17 08:00:00\\\",\\\"2021-07-17 14:00:00\\\",\\\"2021-07-17 20:00:00\\\",\\\"2021-07-18 02:00:00\\\",\\\"2021-07-18 08:00:00\\\",\\\"2021-07-18 14:00:00\\\",\\\"2021-07-18 20:00:00\\\",\\\"2021-07-19 02:00:00\\\",\\\"2021-07-19 08:00:00\\\",\\\"2021-07-19 14:00:00\\\",\\\"2021-07-19 20:00:00\\\",\\\"2021-07-20 02:00:00\\\",\\\"2021-07-20 08:00:00\\\",\\\"2021-07-20 14:00:00\\\",\\\"2021-07-20 20:00:00\\\",\\\"2021-07-21 02:00:00\\\",\\\"2021-07-21 08:00:00\\\",\\\"2021-07-21 14:00:00\\\",\\\"2021-07-21 20:00:00\\\",\\\"2021-07-22 02:00:00\\\",\\\"2021-07-22 08:00:00\\\",\\\"2021-07-22 14:00:00\\\",\\\"2021-07-22 20:00:00\\\",\\\"2021-07-23 02:00:00\\\",\\\"2021-07-23 08:00:00\\\",\\\"2021-07-23 14:00:00\\\",\\\"2021-07-23 20:00:00\\\",\\\"2021-07-24 02:00:00\\\",\\\"2021-07-24 08:00:00\\\",\\\"2021-07-24 14:00:00\\\",\\\"2021-07-24 20:00:00\\\",\\\"2021-07-25 02:00:00\\\",\\\"2021-07-25 08:00:00\\\",\\\"2021-07-25 14:00:00\\\",\\\"2021-07-25 20:00:00\\\",\\\"2021-07-26 02:00:00\\\",\\\"2021-07-26 08:00:00\\\",\\\"2021-07-26 14:00:00\\\",\\\"2021-07-26 20:00:00\\\",\\\"2021-07-27 02:00:00\\\",\\\"2021-07-27 08:00:00\\\",\\\"2021-07-27 14:00:00\\\",\\\"2021-07-27 20:00:00\\\",\\\"2021-07-28 02:00:00\\\",\\\"2021-07-28 08:00:00\\\",\\\"2021-07-28 14:00:00\\\",\\\"2021-07-28 20:00:00\\\",\\\"2021-07-29 02:00:00\\\",\\\"2021-07-29 08:00:00\\\",\\\"2021-07-29 14:00:00\\\",\\\"2021-07-29 20:00:00\\\",\\\"2021-07-30 02:00:00\\\",\\\"2021-07-30 08:00:00\\\",\\\"2021-07-30 14:00:00\\\",\\\"2021-07-30 20:00:00\\\",\\\"2021-07-31 02:00:00\\\",\\\"2021-07-31 08:00:00\\\",\\\"2021-07-31 14:00:00\\\",\\\"2021-07-31 20:00:00\\\",\\\"2021-08-01 02:00:00\\\",\\\"2021-08-01 08:00:00\\\",\\\"2021-08-01 14:00:00\\\",\\\"2021-08-01 20:00:00\\\",\\\"2021-08-02 02:00:00\\\",\\\"2021-08-02 08:00:00\\\",\\\"2021-08-02 14:00:00\\\",\\\"2021-08-02 20:00:00\\\",\\\"2021-08-03 02:00:00\\\",\\\"2021-08-03 08:00:00\\\",\\\"2021-08-03 14:00:00\\\",\\\"2021-08-03 20:00:00\\\",\\\"2021-08-04 02:00:00\\\",\\\"2021-08-04 08:00:00\\\",\\\"2021-08-04 14:00:00\\\",\\\"2021-08-04 20:00:00\\\",\\\"2021-08-05 02:00:00\\\",\\\"2021-08-05 08:00:00\\\"]\",\"rain\":\"[0.090938925,0.21127225,0.21127225,0.29595675,3.79791825,13.157446475,3.852407475,0.7130229749999999,0.085427475,5.831865175000001,3.329785675,0.184485175,0.39688567499999994,0.06639307500000001,9.18575E-4,9.18575E-4,9.18575E-4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.054195925,0.054195925,0.054195925,4.0033234250000005,0.27712637500000004,0.004592875,0.004592875,0.004592875,0.006430024999999999,0.006430024999999999,0.255444025,0.006430024999999999,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.1711173905518,2.2632213905517995,11.731067510767,3.8160868905517997,3.1431858999999998,1.3792134,0.011022899999999999,0.011022899999999999,0.0619382078735,2.6154132078735,3.8513642078735,9.574505431494,0.0,0.0,0.0,0.0,0.25679365000000004,1.7509701500000003,11.045963650000001,2.7646596499999996,0.7621467000000001,5.0035188999999995,0.6198005,0.161595,0.0404173,0.0036743,0.0,0.0456,0.39284700000000006,1.5616596,0.0,0.0456,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.4234225,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0697375,0.0,0.0,0.14991144,1.2084255,8.953913556743,6.55564594,0.273730675,0.008267175,1.944595675,0.873353675,0.017452924999999998,3.8875969250000004,3.119186925,0.8687329250000001,6.2732654,9.114455199999998,0.0036743,0.0492743,0.0,2.4719515000000003,0.43055550000000004,0.716279,0.5406845,2.8057901000000003,0.0,0.0,0.228,0.5509966,0.0697375,0.0,3.8364789999999998,0.8059915,0.051463,0.0,0.6438630000000001,0.1698687,0.0,0.0,0.0,0.0,0.20921249999999997,0.0697375,0.0,0.0,0.0,0.0,1.4070675,0.48816249999999994,0.0697375,0.139475,0.7752,0.0,14.435537100000001,1.5500915,0.43019380000000007,0.124507,0.0,0.0,0.0,0.0,0.5052015000000001,0.205852,0.0,0.0,0.0,0.0,0.0661374,0.0661374,2.6974807,54.631456299999996,49.179549708161,8.8070663419588,13.721576378440002,4.7839067591691995,8.573993,4.081321,43.3873108,12.491981500000001,0.5099130000000001,0.5660930000000001,0.0,0.0654745,0.0,0.0,0.0,0.0,0.004592875,0.004592875,0.004592875,1.015616875,0.45396380000000003,8.6568851,0.2521888,0.06914880000000001,0.0,0.0,2.9468486000000005,0.0,0.0992061,0.025720099999999996,0.025720099999999996,0.1502271,7.2282736000000005,9.0989309,0.27424000000000004,0.597181,2.350446,4.160792000000001,0.0,0.0,0.124507,0.0,0.0,0.0,0.001224766727905,0.2710598,0.001224766727905,0.001224766727905,0.2735093345581,0.024495334558099997,48.836419500000005,9.9051438345581,6.6927059,8.925960400000001,9.5557193,13.634792299999999,0.2736,0.0,0.0,0.0,0.0027557249999999997,0.0027557249999999997,0.0027557249999999997,0.0027557249999999997,23.789045699999996,17.7947324,1.9420681000000002,2.5184421,1.8563227999999998,1.5332092,0.3165335,0.42377100000000006]\",\"q\":\"[]\",\"PR\":\"[[0.0,60.0,70.0,80.0,90.0,100.0,110.0,120.0,130.0,140.0,150.0,160.0,170.0,180.0,190.0,200.0,230.0],[0.0,8.5,10.0,11.6,13.0,14.8,15.7,18.4,20.4,23.0,26.4,30.3,36.0,41.7,48.0,56.0,80.0]]\",\"CalculatedType\":\"1\",\"Im\":\"130\",\"runoffSim\":\"[]\",\"start\":\"\\\"2021-07-02 08:00:00\\\"\",\"KD\":\"[0.94, 0.94, 0.94, 0.94, 0.94, 0.94, 0.96, 0.96, 0.97, 0.97, 0.97, 0.97]\",\"clen\":\"6\",\"M\":\"17\",\"PA0\":\"121.1\"}";
        Map data = JSON.parseObject(a, Map.class);
        P_RWLL obj = new P_RWLL(data);
        System.out.println(obj.predict());
    }

}